package bb.lanxing.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.core.content.FileProvider;
import androidx.core.net.MailTo;
//import gdut.bsx.share2.ShareContentType;
import java.io.File;


public class PostMan {

    public static class Email {
        private Intent intent;

        public Intent getIntent() {
            return this.intent;
        }

        public Email() {
            Intent intent = new Intent("android.intent.action.SEND");
            this.intent = intent;
            intent.setData(Uri.parse(MailTo.MAILTO_SCHEME));
        }

        public Email setTitle(String title) {
            this.intent.putExtra("android.intent.extra.SUBJECT", title);
            return this;
        }

        public Email setBody(String bdoy) {
            this.intent.putExtra("android.intent.extra.TEXT", bdoy);
            return this;
        }

        public Email sendTo(String emailAdd) {
            this.intent.putExtra("android.intent.extra.EMAIL", new String[]{emailAdd});
            this.intent.setType("message/rfc822");
            return this;
        }

        public Email copyTo(String emailAdd) {
            this.intent.putExtra("android.intent.extra.CC", emailAdd);
            return this;
        }

        public Email blindCopyTo(String emailAdd) {
            this.intent.putExtra("android.intent.extra.BCC", emailAdd);
            return this;
        }

        public Email putFile(Context context, File file) {
            this.intent.putExtra("android.intent.extra.STREAM", FileProvider.getUriForFile(context, "bb.lanxing.fileprovider", file));
            return this;
        }
    }

    public static class ShareFile {
        private Intent intent;

        public Intent getIntent() {
            return this.intent;
        }

        public ShareFile() {
            Intent intent = new Intent("android.intent.action.SEND");
            this.intent = intent;
            intent.setType("*/*");
        }

        public ShareFile putFile(Context context, File file) {
            this.intent.putExtra("android.intent.extra.STREAM", FileProvider.getUriForFile(context, "bb.lanxing.fileprovider", file));
            return this;
        }
    }

    public static void senEmail(Context context, Email email, String chooseText) {
        context.startActivity(Intent.createChooser(email.getIntent(), chooseText));
    }

    public static void shareFile(Context context, ShareFile shareFile, String chooseText) {
        context.startActivity(Intent.createChooser(shareFile.getIntent(), chooseText));
    }
}
